<template>
  <el-container class="layout-container">
    <el-header style="font-size: 12px">
      <div class="logo-container">
        <img src="../assets/logo.png" alt="Your Logo" class="logo"/>
        <el-button type="primary" text style="margin-left: 20px" @click="toHome">首页</el-button>
      </div>
      <div class="toolbar">
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
           {{ currentUserInfo.userName }}
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="150px">
        <el-scrollbar>
          <el-menu router :default-openeds="['1']" :default-active="onRoutes">
            <el-sub-menu index="1">
              <template #title>
                <el-icon><icon-menu /></el-icon>人事管理
              </template>
              <el-menu-item-group>
                <el-menu-item index="/hr/userBasicList">信息查询</el-menu-item>
                <el-menu-item index="/hr/userBasicRegisterList">人员登记</el-menu-item>
<!--                <el-menu-item index="/hr/userBasicAuditList">数据审核</el-menu-item>-->
                <el-menu-item index="/hr/userBasicStartSalaryList">人员起薪</el-menu-item>
<!--                <el-menu-item index="/hr/userBasicStartSalaryList">人员起薪</el-menu-item>-->
<!--                <el-menu-item index="/hr/userBasicAgreementList">合同管理</el-menu-item>-->
                <el-menu-item index="/hr/employmentExamine">聘期考核</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
            <el-sub-menu index="2">
              <template #title>
                <el-icon><icon-menu /></el-icon>薪酬福利
              </template>
              <el-menu-item-group>
                <el-menu-item index="/hr/salaryList">工资查询</el-menu-item>
<!--                <el-menu-item index="/hr/noSalaryList">人员起薪</el-menu-item>-->
                <el-menu-item index="/hr/houseFund">公积金调整</el-menu-item>
                <el-menu-item index="/hr/salaryLevel">薪级调整</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
            <el-sub-menu index="3">
              <template #title>
                <el-icon><setting /></el-icon>职称评审
              </template>
              <el-menu-item-group>
                <el-menu-item index="3-1">Option 1</el-menu-item>
                <el-menu-item index="3-2">Option 2</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
            <el-sub-menu index="4">
              <template #title>
                <el-icon><setting /></el-icon>进修访学
              </template>
              <el-menu-item-group>
                <el-menu-item index="3-1">Option 1</el-menu-item>
                <el-menu-item index="3-2">Option 2</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-main>
        <RouterView />
      </el-main>
    </el-container>

  </el-container>

</template>

<script lang="ts" setup>
import { Menu as IconMenu, Setting } from '@element-plus/icons-vue'
import {computed, onMounted, ref} from 'vue';
import { useRouter, useRoute } from 'vue-router'
import {ElMessage} from "element-plus";
import SystemUser from '@/api/SystemUser.js';
import { ArrowDown } from '@element-plus/icons-vue'
const router = useRouter()
const route = useRoute()

const onRoutes = computed(() => {return route.path;});

const currentUserInfo = ref({
  id: '',
  userAccount: '',
  userName: '',
  userPassword: '',
  userPasswordSalt: '',
  roleIds: []
});

onMounted(() => {
  SystemUser.currentUserInfo()
      .then(res => {
        currentUserInfo.value = res.data
      })
});


const handleCommand = (command: string | number | object) => {
  if ('logout' === command) {
    SystemUser.loginOut()
        .then(res => {
          router.push({ name: 'login'});
        })
  } else if ('personalCenter' === command) {
    ElMessage("进入个人中心")
  }
}

const toHome = () => {
  router.push({ name: 'home'});
}

</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}

.layout-container {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
.layout-container .el-header {
  position: relative;
  background-color: #d5e1e9;
  color: var(--el-text-color-primary);
}
.layout-container .el-aside {
  color: var(--el-text-color-primary);
}
.layout-container .el-menu {
  border-right: none;
}
.layout-container .el-main {
  padding: 0;
}
.layout-container .toolbar {
  height: 100%;
  width: 50%;
  float: right;
  display: inline-flex;
  align-items: center;
  justify-content: right;
}
.logo-container {
  height: 100%;
  width: 50%;
  float: left;
  display: flex;
  align-items: center;
}

.logo {
  height: 50px;
  width: auto;
}
</style>
